/*
 *	Player.h
 *	
 *
 *
 *
 */
#ifndef PLAYER_H
#define PLAYER_H
//----

#include <iostream>
#include <string>
#include "MooseFlag.h"
#include <Ogre/Ogre.h>
#include <OIS.h>
#include "InputManager.h"


using std::string;

using Ogre::Vector3;
using Ogre::Quaternion;
using Ogre::SceneManager;
using Ogre::SceneNode;
using Ogre::Radian;
using Ogre::Math;
using Ogre::Real;


class Player : public OIS::KeyListener{
private:
	string name;
	int score;

	Vector3 position;			// position in world coord.
	Quaternion orientation;		// ogre uses quaternion instead of rotation matrices.// current velocity
	Vector3 acceleration;		// current acceleration
	
	Ogre::SceneManager *sceneMgr;
	
	MooseFlag *flags;
	
	int pitchy;
	int pitchyback;
	int rolly;
	int rollyright;
	
	int do_acc;
	int do_rot;	
	
	Vector3 velocity;	
	bool atGround;
	Vector3 gravity;	
	
	Ogre::RaySceneQuery* raySceneQuery;
	Ogre::RaySceneQuery* raySceneQueryFront;
	Ogre::RaySceneQuery* raySceneQueryBack;
	Ogre::RaySceneQuery* raySceneQueryLeft;
	Ogre::RaySceneQuery* raySceneQueryRight;
	
	SceneNode *node;
	
	Radian rotation;
	
	OIS::KeyCode keyLeft, keyRight, keyUp, keyDown;
	
public:
	// constructor - set's name and adds the mesh in correct scale into the scenemanager. --------------------------
	Player::Player(string name, SceneManager *sceneMgr, char *meshfile, double scale, MooseFlag *flags, bool isP1);
	
	// place initializes translation and rotational variables. ----------------------------------------------------
	void Player::place(Vector3 pos, Quaternion ori, Vector3 vel, Vector3 acc);
	
	// Set do_* variables according to keypress ---------------------------------------------------------------------
	bool Player::keyPressed(const OIS::KeyEvent &e);
	
	// 	We released a key, set its do_* to 0 ---------------------------------------------------------------------
	bool Player::keyReleased(const OIS::KeyEvent &e);
	
	// Check against ground and move SceneNode	---------------------------------------------------------------------
	void Player::updateColl();
	
	// Update variables and move SceneNode	---------------------------------------------------------------------
	void Player::update(Real timeSinceLastFrame);
	
	inline SceneNode* Player::getNode() {return node;}
	inline Vector3 Player::getVel() {return velocity;}

};
#endif